package com.leetcode.simple;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 题扣 算法简单
 *
 * @author Administrator
 */
public class LeetCodeSimple {

    public static void main(String[] args) {
        // 两数之和
        int[] nums = {3, 2, 3};
        int target = 6;
        int[] sum = sum(nums, target);
        System.out.println(Arrays.toString(sum));
    }

    private static int[] sum(int[] nums, int target) {
        final int length = nums.length;
        Map<Integer, Integer> map = new HashMap<>(length);
        for (int i = 0; i < length; i++) {
            map.put(i, nums[i]);
        }
        for (int i = 0; i < length; i++) {
            int j = i + 1;
            while (j < length) {
                if (nums[i] + map.get(j) == target) {
                    if (i < j) {
                        return new int[]{i, j};
                    } else {
                        return new int[]{j, i};
                    }
                } else {
                    j++;
                }
            }
        }
        return null;
    }
}
